<?php  
//新闻的修改
 include_once("./com.php");
 error_reporting(E_ALL^E_NOTICE^E_WARNING);
date_default_timezone_set("PRC");
session_start();

function msg($msg, $url=''){
		if($url == ''){
			$ad = "window.history.go(-1)";
		}else{
			$ad = "window.location.href='{$url}'";
		}
		exit("<script>alert('{$msg}');{$ad};</script>");
	}

 $nid=$_GET['nid'];
 $res="select * from news where nid=$nid";
 $rty=mysql_query($res);
 $sds=mysql_fetch_assoc($rty);
 $antitle=$sds['ntitle'];
 $animg=$sds['nimg'];
 $andescp=$sds['ndescp'];
 $anname=$sds['nname'];
 $ankeyword=$sds['nkeyword'];
 $animg=$sds['nimg'];
 $aanimg=explode("-",$sds['nimg']);

 	if(isset($_POST['sub'])){
 		$ntitle = $_POST['ntitle'];
 		$nimg = $_FILES['nimg'];
 		$nname = $_POST['nname'];		
 		$ndescp = strip_tags($_POST['ndescp']);
 		$nkeyword = $_POST['nkeyword'];
 		$path = "../uploads1";
 	  	if(!empty($nimg['name'][0])){
 	  		foreach ($nimg['name'] as $k=>$v) {
 	  			foreach ($nimg['tmp_name'] as $ko=>$vo) {
	 	  			if($k==$ko)	{  	
	 					move_uploaded_file($vo,$path."/".$v);
	 				}
 	  			}
 	  			$img[]=$v;
 	  		}
 	  		$imgg=implode("-",$img);



 	  		$upl="update news set nimg='$imgg' where nid='$nid'";
 	  		mysql_query($upl);
 	  		$uimg=mysql_affected_rows();
 	  	}


	if (empty($_POST['ntitle'])) {
		msg('新闻标题不能为空');
	}
		if (empty($_POST['nname'])) {
		msg('新闻作者不能为空');
	}
if (empty($_POST['ndescp'])) {
		msg('新闻内容不能为空');
	}

 		$nem = "update news set ntitle='$ntitle',nname='$nname',ndescp='$ndescp',nkeyword='$nkeyword' where nid='$nid'";
 		mysql_query($nem);
 		$nem=mysql_affected_rows();
 		if($uimg>0 or $nem>0){
 			echo "<script>
				alert('修改成功')
				location.href='news.php'
				</script>";
 		}else{
 			echo "<script>
				alert('修改失败')
				location.href='news_edit.php'
				</script>";								
 		}
 	}

 ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主体部分</title>
<base target="_self">
<link rel="stylesheet" type="text/css" href="skin/css/base.css" />
<link rel="stylesheet" type="text/css" href="skin/css/main.css" />
</head>
<body leftmargin="8" topmargin='8'>
<table width="98%" align="center" border="0" cellpadding="3" cellspacing="1" bgcolor="#CBD8AC" style="margin-bottom:8px;margin-top:8px;">
  <tr>
    <td background="skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' colspan="2"><span><img src='skin/images/frame/arr3.gif' style='margin-right:10px;'>修改新闻</span></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>
		<table style="margin-bottom:8px;margin-top:8px;margin-left:20px;">
			<form  action="" method="post" enctype="multipart/form-data">
			<tr>
				<td width="100px;">新闻标题:</td>
				 <td><input type="text" name="ntitle" value="<?=$antitle?>"></td>
			</tr>				
			<tr>
				 <td>新闻作者：</td>
				 <td><input type="text" name="nname" value="<?=$anname?>"></td>
			</tr>  		
			<tr>
				<td>关键字：</td>
				<td><input type="text" name="nkeyword" value="<?=$ankeyword?>"></td>
			</tr>
			<tr>
				 <td>新闻图片：</td>
				 <td><input type="file" name="nimg[]" value="" multiple>
				<?php  foreach ($aanimg as $value) {
					echo "<img src='../uploads1/$value' width='20px'>";
				}?>
				 </td>
			</tr> 
			<tr>
				<td>新闻内容：</td>
				<td>
				<?php
				include_once("./fckeditor/fckeditor.php");
				$fckeditor = new FCKeditor("ndescp");//定义默认值 name
				$fckeditor->Width = "300px";//定义编辑器的宽度
				$fckeditor->Height = "200px";//定义编辑器的高度
				$fckeditor->Value = "$andescp";//定义默认值
				$fckeditor->BasePath='./fckeditor/';
				$fckeditor->ToolbarSet = "Basic";
				$fckeditor->Create();//创建编辑器
				?>
				</td>				 
			</tr>  
			<tr>
				 <td colspan="2" align="center" height="40px">
				 	<input type="submit" name="sub" value=" 修改 " class="coolbt2"></td>
			  </tr>
		</form>
			</tr>		
		</table>
	</td>
  </tr>
</table>
</body>
</html>







